#ifndef VLGAMEELEMENTSCONTEXTWIDGET_H
#define VLGAMEELEMENTSCONTEXTWIDGET_H

#include "vlcontextwidget.h"
#include <QComboBox>
#include <QSignalMapper>
#include "GameElementTool.h"
#include <QList>

#define MAX_BUF_SIZE 30

class VLGameElementsContextWidget : public VLContextWidget
{
    Q_OBJECT
    explicit VLGameElementsContextWidget(QWidget *parent = 0);

    char nameBuf[MAX_BUF_SIZE];
    void makeName(GameElement* e);
public:
    static
    VLGameElementsContextWidget* getInstance();
    
    int getDoorFaceSide(){return doorFaceSideBox->currentIndex();}
    int getSpeed(int speed);
    int getRangeA(int val);
    int getRangeB(int val);
    int getSpikesDamage(int val);
    int getLadderOrientation(){return ladderOrientationBox->currentIndex();}
    int getSwitchCurrentTarget();
    void updateGUIElement(int elem);
    void updateSwitchTargetList(ElementSwitch * e);
    GAME_ELEMENT_TYPE getGUICurrentElement(){return currentElement;}
signals:
    void doorFaceSideChanged(int);
    void enemySpeedChanged(int);
    void enemyWidthChanged(int);
    void enemyDepthChanged(int);
    void spikesDamageChanged(int);
    void ladderOrientationChanged(int);
    void switchStateChanged(int);
    void elementChanged(int);
    
public slots:
    void setCurrentElement(int elem);
    void setDoorFaceSide(int index);
    void setEnemySpeed(int val);
    void setEnemyWidth(int val);
    void setEnemyDepth(int val);
    void setSpikesDamage(int val);
    void setLadderOrientation(int index);
    void removeSwitchTarget();
    void updateComboBox(int index);

private:

    //enum ELEMENTS {DOOR, ENEMY, SPIKES, LADDER, SWITCH};
    QMap<GAME_ELEMENT_TYPE, QList<QWidget *> > *widgets;

    QHBoxLayout *layout;
    QLabel *nameLabel;
    GAME_ELEMENT_TYPE currentElement;

    void setDefaults();

    QLabel *elementsLabel;
    QComboBox *elementsBox;
    QStringList *elementsOptions;
    void setupElements();

    QWidget *doorSubCtx;
    QComboBox *doorFaceSideBox;
    QStringList *doorOptions;
    void setupDoorSubContext();

    QWidget *enemySubCtx;
    QSpinBox *enemySpeedBox;
    QSpinBox *enemyWidth;
    QSpinBox *enemyDepth;
    QLabel *enemySpacer;
    void setupEnemyContext();

    QWidget *spikesSubCtx;
    QSpinBox *spikesDamageBox;
    void setupSpikesContext();

    QWidget *ladderSubCtx;
    QComboBox *ladderOrientationBox;
    QStringList *ladderOrientations;
    void setupLadderContext();

    QWidget *switchSubCtx;
    QComboBox *switchTargetsBox;
    QPushButton *switchTargetRemove;
    QStringList *switchTargets;
    void setupSwitchContext();

    void hideWidgets(QList<QWidget *> visibleWidgets);
    void showWidgets(QList<QWidget *> hiddenWidgets);

};

#endif // VLGAMEELEMENTSCONTEXTWIDGET_H
